import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1543372366833_2522';

  // add your config here
  config.middleware = ['responseHandler'];
  // upload filetype whitelist
  config.multipart = {
    whitelist: [
      '.png',
      '.gif',
      '.jpg',
      '.txt',
      '.conf',
    ],
  };
  config.bizerror = {
    breakDefault: false, // disable default error handler
    sendClientAllParams: false, // return error bizParams to user
    interceptAllError: false, // handle all exception, not only bizError exception
  };

  // 分类
  config.categories = {
    'share': '分享',
    'ask': '问答',
    'test': '测试',
  };
  
  // 上传文件存放路径
  config.uploadDir = 'app/public/uploads';

  
  // 关闭安全威胁csrf的防范
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
      ignore: ctx => {
        const ipReg = /^(172\.17|127\.0)/;
        return ipReg.test(ctx.ip);
      },
    },
    // domainWhiteList: ['*']
  };

  config.cors = {
    origin: '*',     //处理跨域请求
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
    // credentials: true,
    // credentials: true,
  };

  // token凭证
  config.jwtSecret = 'sixdre';
  // cookie name config
  config.auth_cookie_name = 'token';

  // 七牛
  config.qiniu_config = {
    accessKey: 'hM5qMEJfJNy2thESXZB2MMAx6H83mGGaeMAwyFfb',
    secretKey: 'bNVNnsynNTyY9wbVS5KIybQrCSnNvs5g1WeZybaa',
    bucket: 'myblog',
    origin: 'http://osf6cl53d.bkt.clouddn.com/',
  };

  // 阿里云oss
  config.alioss_config = {
    region: 'oss-cn-beijing',
    accessKeyId: 'LTAIfcVcQNHhHF0Q',
    accessKeySecret: 'DX2B59kq01YLHMV5AOYUjRCODSkbSv',
    bucket: 'sixdre',
  };
  return config;
};
